package com.sofoscorp.android.gestcobranzamobile;

import java.util.ArrayList;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class VPAGO_BO {
	private String gv_tabName = "VPAGO";
	private ConexionDB go_conexDB;
	private Cursor gc_VPAGO;
	private SQLiteDatabase go_db;
	
	private VPAGO_Str[] gt_VPAGO = null;
	String[] gt_campos = new String[]{"HBKID", "ZLSCH", "TEXTO"};
	
	public VPAGO_BO(){
		go_conexDB = new ConexionDB();
	}
	
	public VPAGO_Str[] get_TableByKey(String ivHBKID){
		ArrayList<VPAGO_Str> lt_List = new ArrayList<VPAGO_Str>();
		String lv_Where = "HBKID = ?";
		String[] lt_WhereArgs;
		
		if(ivHBKID.equals("") || ivHBKID.equals(null)){
			gt_VPAGO = null;
		}else {
			lt_WhereArgs = new String[]{ivHBKID};
			
			//Pasar el Path de DB
			go_conexDB.serialization(go_conexDB.C_PATH_FROMSAP);

			//Verificar si existe conexion con la DB
			if (go_conexDB.checkConexDB()) {

				//Obtener la DB
				go_db = go_conexDB.getGo_DB();
				
				try {
					//Ejecutar Select a la DB
					gc_VPAGO = go_db.query(gv_tabName, gt_campos, lv_Where, lt_WhereArgs, null, null, null, null);
					if (gc_VPAGO.moveToFirst()) {
						//Recorrer el cursor
						do {
							lt_List.add(new VPAGO_Str(	gc_VPAGO.getString(0), 
														gc_VPAGO.getString(1), 
														gc_VPAGO.getString(2)));
						} while (gc_VPAGO.moveToNext());
						gt_VPAGO = lt_List.toArray(new VPAGO_Str[0]);
					}else{
						lt_List = null;
						gt_VPAGO = null;
					}
				} catch (Exception e) {
					// TODO: handle exception
				}
			}else{
				lt_List = null;
				gt_VPAGO = null;
			}
		}

		go_db.close();
		gc_VPAGO.close();
		return gt_VPAGO;
	}
}
